open file, "<D:/1.txt" or die $!;

my $close = 0 ;
my $open = 0;
my $flag = 0;
while(<file>)
{
	# if($_ = 
	print $_;
	if($_ =~ m/\}/)
	{
		$open++;
	}
	if($_ =~ m/\{/)
	{
		$close++;
	}
	
	# Check end condition
	if($open > 0 && $close > 0 && $open == $close)
	{
			$flag = 1 ;
			print "\nEND NOW ";
			$open = 0 ; 
			$close = 0;
	}
}
print "\n",$close, " " , $open ,"\n";
                                    
                                    
sub regex_or {
  my $string = shift;
  $string =~ s/(?:^ +)||(?: +$)//g;
  return $string;
}                  